package org.vectrics.recruiter.struts;

import javax.servlet.jsp.JspException;

import org.apache.log4j.Category;
import org.vectrics.SystemException;
import org.vectrics.company.Company;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.struts.Request;
import org.vectrics.struts.UserBufferManager;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;
import org.vectrics.user.Person;

public class BufferAddAction extends VectricsStrutsAction {
    private static Category log = Category.getInstance(BufferAddAction.class);
    
	@Override
	protected String doExecute(VectricsActionData actionData) throws JspException {
		Request request = actionData.getRequest();
		UserBufferManager bufferManager = new UserBufferManager();	
		log.debug("execute() called, reading http parameters");
	    Long recordId = new Long(request.getParameter("recordId"));
	    String objectType = request.getParameter("objectType");
		if (objectType.equals(Job.OBJECT_TYPE)) {
		    Job job = RecruitServiceLocator.getJobProvider().findJob(recordId);
		    bufferManager.addBufferedObject(request, job);
		    
		} else if (objectType.equals(Person.OBJECT_TYPE)) {
		    Person person = CoreServiceLocator.getPersonService().findPersonById(recordId);
		    bufferManager.addBufferedObject(request, person);
		} else if (objectType.equals(Company.OBJECT_TYPE)) {
		    Company company = CoreServiceLocator.getCompanyService().findCompany(recordId);
		    bufferManager.addBufferedObject(request, company);
		} else {
		    throw new SystemException("Do not know how to handle buffer object: " + objectType);
		}
		

		return ("success");
	}



}